package com.ruoyi.business.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.business.domain.DeliveryBillentryPound;
import com.ruoyi.business.service.DeliveryBillentryPoundService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 发货物料明细地磅Controller
 *
 * @author JerryLu
 * @date 2024/9/7 14:23
 */
@RestController
@RequestMapping("/system/delivery_billentry_pound")
public class DeliveryBillentryPoundController extends BaseController {
    @Autowired
    private DeliveryBillentryPoundService billentryPoundService;

    /**
     * 查询发货物料明细地磅列表
     */
    @PreAuthorize("@ss.hasPermi('system:delivery_billentry_pound:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeliveryBillentryPound deliveryBillentryPound) {
        startPage();
        List<DeliveryBillentryPound> list = billentryPoundService.queryList(deliveryBillentryPound);
        return getDataTable(list);
    }

    /**
     * 导出发货物料明细地磅列表
     */
    @PreAuthorize("@ss.hasPermi('system:delivery_billentry_pound:export')")
    @Log(title = "发货物料明细地磅", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeliveryBillentryPound deliveryBillentryPound) {
        List<DeliveryBillentryPound> list = billentryPoundService.queryList(deliveryBillentryPound);
        ExcelUtil<DeliveryBillentryPound> util = new ExcelUtil<DeliveryBillentryPound>(DeliveryBillentryPound.class);
        util.exportExcel(response, list, "发货物料明细地磅数据");
    }

    /**
     * 获取发货物料明细地磅详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:delivery_billentry_pound:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(billentryPoundService.getById(id));
    }

    /**
     * 获取发货物料明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:delivery:index')")
    @GetMapping(value = "/receiving/{deliveryId}")
    public AjaxResult getReceiptInfo(@PathVariable("deliveryId") String deliveryId) {
        QueryWrapper<DeliveryBillentryPound> query = Wrappers.query();
        query.eq("delivery_id", deliveryId);
        List<DeliveryBillentryPound> list = billentryPoundService.list(query);
        return success(list);
    }

    /**
     * 新增发货物料明细地磅
     */
    @PreAuthorize("@ss.hasPermi('system:delivery_billentry_pound:add')")
    @Log(title = "发货物料明细地磅", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeliveryBillentryPound deliveryBillentryPound) {
        return toAjax(billentryPoundService.save(deliveryBillentryPound));
    }

    /**
     * 修改发货物料明细地磅
     */
    @PreAuthorize("@ss.hasPermi('system:delivery_billentry_pound:edit')")
    @Log(title = "发货物料明细地磅", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeliveryBillentryPound deliveryBillentryPound) {
        return toAjax(billentryPoundService.updateById(deliveryBillentryPound));
    }

    /**
     * 删除发货物料明细地磅
     */
    @PreAuthorize("@ss.hasPermi('system:delivery_billentry_pound:remove')")
    @Log(title = "发货物料明细地磅", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(billentryPoundService.removeBatchByIds(Arrays.asList(ids)));
    }
}

